package com.corn.turorial.spring.actuator;

import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ThreadLocalRandom;

/**
 * @author : Jim Wu
 * @version 1.0
 * @function :
 * @since : 2021/2/4 14:55
 */

@Component
public class MyHealthEndPointIndicator implements HealthIndicator {
    @Override
    public Health health() {
        if (ThreadLocalRandom.current().nextBoolean()) {
            return Health.up().withDetail("system", "success").build();
        }
        Map<String, Object> errorMsg = new HashMap<>();
        errorMsg.put("errorCode", "400");
        errorMsg.put("errorMsg", "system is down");
        return Health.down().withDetails(errorMsg).build();
    }
}
